

<!-- 三级分类商品 -->
<template>
	<view>
		<!-- header部分 -->
		<view class='header-Container header-height'>
			<view class="header-bg"></view>
			<navHeader :pageTitle="categoryName" rightBtnType="msgCenter" colorTheme="white" @toggleMenuListHandler="toggleMenuListHandler">
			</navHeader>
		</view>
		
		
		<!-- 筛选框 -->
		<view class="filterBar headerNext">
			<navbar :headerTop='headerTop' :headerPosition='headerPosition' @getAction="tabClick"></navbar>	
		</view>
		
		<!-- 大图列表 -->
		<view class="good_list" v-if="listType==0">
			<goodList v-if="goodsList && goodsList.length" :list='goodsList'></goodList>
			<g-empty v-else></g-empty>
		</view>
		
		<!-- 横向列表 -->
		<view class="good_list2" v-else>
			<goodListtransverse v-if="goodsList && goodsList.length" :list='goodsList'></goodListtransverse>
			<g-empty v-else></g-empty>
		</view>
		
		<!-- 详情菜单 -->
		<view v-if="showDetailMenu" @click="toggleMenuListHandler()" class="detailMenu-Container">
			<detailMenu></detailMenu>
		</view>
	</view>
</template>

<script>
	import goodList from '@/components/goodList/goodList';
	import goodListtransverse from '@/components/goodList/goodList-transverse';
	import navbar from '@/components/navbar/navbar';
	import navHeader from '@/components/nav-header/nav-header';
	import detailMenu from "@/components/detailMenu/detailMenu";
	
	export default {
		components: {
			goodList,
			navbar,
			goodListtransverse,
			navHeader,
			detailMenu
		},
		data() {
			return {
				icon:{ 
					delete: '/static/images/list/delete.png',
					return: '/static/images/common/return-white.png',
					top: '/static/images/index/top.png',
					search: '/static/images/index/search.png',
					msgCenterWhite: '/static/images/common/msg-center-white.png'
				},
				
				//详情菜单
				showDetailMenu: false,
				
				search: '',
				headerPosition: "fixed",
				headerTop: "0px",
				loadingType: 'more', //加载更多状态
				filterIndex: 0,
				priceOrder: 0, //1 价格从低到高 2价格从高到低
				listType: 0,
				searching: false,
				getFocus: false,
				
				sortType: 0,
				goodsList: [], 
				windowHeight: 100,
				
				categoryId: "",
				categoryName: "",
				
				//分页相关
				pageNum: 1,
				pageSize: 10
			};
		},

		onLoad(options) {
			
			this.categoryId = options.categoryId;
			this.categoryName = options.categoryName;
			this.getThirdGoodsList();
			
			
			// 获取页面高度
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					console.log(res.windowHeight) // 获取可使用窗口高度
					that.windowHeight = (res.windowHeight * (750 / res.windowWidth)); //将高度乘以换算后的该设备的rpx与px的比例
					that.windowHeight = that.windowHeight - 91;
					console.log('可用高度==>' + that.windowHeight); //最后获得转化后得rpx单位的窗口高度
				}
			});
		},
		onShow() {
			this.showDetailMenu = false;
		},
		methods: {
			
			//详情菜单
			toggleMenuListHandler() {
				this.showDetailMenu = !this.showDetailMenu;
			},
			
			
			//列表筛选条件
			tabClick(params) {
				
				if(params.listFlag) {
					this.listType = params.listType;
				}else if(params.sortFlag) {
					if(params.sortType == 3) {
						this.sortType = params.priceSort;
					}else {
						this.sortType = params.sortType;
					}
					
					this.pageNum = 1;
					this.getThirdGoodsList();
				}
			},
			
			// 搜索框获取焦点,出现搜索页
			beSearch() {
				console.log('searching');
				this.searching = true;
			},
			
			
			//商品列表
			getThirdGoodsList() {
				
				var that = this;
				that.$api.globalUtil.requestAjax({
					url: '/GoodsApi/commodityClassificationListApi',
					method: "POST",
					data: {
						isSearch: false,
						pageNum: that.pageNum, //页码
						pageSize: that.pageSize,//显示条数
						sort: that.sortType, //综合排序:null 销量排序:1 新品排序:2 价格ASC:3 价格DESC:4
						goodsCategoryThird: that.categoryId
					},
					success: function(res) {
						if(res.data.success) {
							
							if(res.data.response.results.length) {
								if(that.pageNum == 1) {
									that.goodsList = res.data.response.results;
								}else {
									that.goodsList = that.goodsList.concat(res.data.response.results);
								}
							}else {
								that.$api.msg("没有更多数据！");
							}
						}
					}
				});
			}
		},
		onPullDownRefresh() {
			var that = this;
			that.pageNum = 1;
			
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1500);
			
			that.getThirdGoodsList();
		},
		onReachBottom() {
			var that = this;
			that.pageNum = that.pageNum + 1;
			
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1500);
			
			that.getThirdGoodsList();
		}
	}
</script>

<style lang="scss">
	
	// header部分
	.header-Container {
		width: 100%;
		height: 176rpx;
		overflow: hidden;
		box-shadow: 0px 1rpx 1rpx 0px rgba(0, 0, 0, 0.08);
		background: rgba(255, 255, 255, 1);
		
		.header-bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background:#FE5E49;
		}
	
		.leftBtns {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
	
			.back {
				margin-left: 17rpx;
				width: 44rpx;
				height: 44rpx;
			}
		}
	
		.title {
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
			line-height: 86rpx;
			text-align: center;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(51, 51, 51, 1);
		}
	}
	
	
	
	// 商品列表
	/deep/.list-pages {
		padding: 0 30rpx;
		
		.list-block {
			margin-bottom: 30rpx;
			width: 336rpx;
			box-shadow: 0 2rpx 10rpx 0 rgba(103,103,103,0.1);
			border-radius:10rpx;
			
			.list-poster {
				width: 336rpx;
				height: 336rpx;
			}
		}
	}
	.good_list2{
		width: 100%;
		background-color: white;
	}
</style>




